%GLOBAL CWD; %LET CWD = %SUBSTR(%SYSGET(SAS_EXECFILEPATH), 1, %EVAL(%LENGTH(%SYSGET(SAS_EXECFILEPATH)) - %LENGTH(%SYSGET(SAS_EXECFILENAME)) - 1));
%INCLUDE "&CWD\TOOLS.SAS";

/* SET ELI & CLUSTER */
%LET ELI = FN011;
%LET CLUSTER = 01;

/* IDENTIFYING HANDLE */
%LET COM = &ELI._&CLUSTER.;

/* ITEM-SPECIFIC RIGHT HAND SIDE VARIABLES */
%LET RHS= 
    A2-A5 A99SP B2-B4 B99SP D2 E1 F1 U3-U5 U7-U9 U99SP
    V2 V98SP V99SP W2 W3 BRAND1-BRAND3 
    MNAMT MNAMTSQ
    ;

%LET STYR=0201;
%LET FIRSTPER=20&STYR;
%LET LASTPER = 200709;
%LET STDUM=D&STYR;
%LET RHYRS= 
        D0202--D0709;

%LET NSPER = %COUNTMONTHS(&FIRSTPER, &LASTPER);
%LET NVEC = %EVAL(&NSPER + %COUNTWORDS(&RHS));

/* DEFINE ITEM-SPECIFIC PRICE EDITS */
%MACRO EDITS;   
    IF C="C1";
    IF PRICE GE .00478;
    IF PRICE LE .1;
    IF BSNS_TYPE_CD NE "";
    IF LNAMT =. THEN DELETE;
    IF LNAMT LE 7;
%MEND;

/* DEFINE ITEM-SPECIFIC DUMMIES */
%MACRO VARS;
    U1=(U="U1"); U2=(U="U2"); U3=(U="U3"); U4=(U="U4"); 
    U5=(U="U5"); U6=(U="U6"); U7=(U="U7"); U8=(U="U8"); 
    U9=(U="U9"); 
    U99SP=(U="U99"); 
    *;
    V1=(V="V1"); V2=(V="V2"); V3=(V="V3"); V4=(V="V4"); 
    V5=(V="V5"); V6=(V="V6"); V7=(V="V7"); V8=(V="V8"); 
    V98SP=(V="V98"); V99SP=(V="V99"); 
    *;
    W2=(W="W2"); W3=(W="W3");
    *;
    IF X99 NE "";
    if index(X99,'**********') OR INDEX(X99,'**********') THEN BRAND1=1; ELSE BRAND1=0;
    if index(X99,'**********') THEN BRAND2=1; ELSE BRAND2=0;
    if index(X99,'**********') OR INDEX(X99,'**********') 
    OR INDEX(X99,'**********') OR INDEX(X99,'**********') 
    OR INDEX(X99,'**********') OR SUBSTR(X99,1,3)="**********" THEN BRAND3=1; ELSE BRAND3=0;
    ARRAY SPECARRAY (*) A B D U V E F W;
    DO COUNT=1 TO DIM(SPECARRAY);
        IF SPECARRAY(COUNT)="" THEN DELETE;
    END;
%MEND;

LIBNAME IN "&CWD\DATA";
LIBNAME OUT "&CWD\DATA";

FILENAME OUTLOGS "&CWD\OUTPUT\LOGINDEXES.XLS";
FILENAME OUTCONTS "&CWD\OUTPUT\LOGCONTRIBS.XLS";
FILENAME OUTDISCS "&CWD\OUTPUT\DISCOUNTS.XLS";
FILENAME OUTPCTLS "&CWD\OUTPUT\PCTLS.XLS";

%INCLUDE "&CWD\TABLESTOBUILD.SAS";